package cn.home.resident.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.home.common.annotation.Log;
import cn.home.common.core.controller.BaseController;
import cn.home.common.core.domain.AjaxResult;
import cn.home.common.enums.BusinessType;
import cn.home.resident.domain.HomeHealthlogType;
import cn.home.resident.service.IHomeHealthlogTypeService;
import cn.home.common.utils.poi.ExcelUtil;
import cn.home.common.core.page.TableDataInfo;

/**
 * 健康记录类型Controller
 * 
 * @author homedoctor
 * @date 2025-04-11
 */
@RestController
@RequestMapping("/type/type")
public class HomeHealthlogTypeController extends BaseController
{
    @Autowired
    private IHomeHealthlogTypeService homeHealthlogTypeService;

    /**
     * 查询健康记录类型列表
     */
    @PreAuthorize("@ss.hasPermi('type:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(HomeHealthlogType homeHealthlogType)
    {
        startPage();
        List<HomeHealthlogType> list = homeHealthlogTypeService.selectHomeHealthlogTypeList(homeHealthlogType);
        return getDataTable(list);
    }

    /**
     * 导出健康记录类型列表
     */
    @PreAuthorize("@ss.hasPermi('type:type:export')")
    @Log(title = "健康记录类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HomeHealthlogType homeHealthlogType)
    {
        List<HomeHealthlogType> list = homeHealthlogTypeService.selectHomeHealthlogTypeList(homeHealthlogType);
        ExcelUtil<HomeHealthlogType> util = new ExcelUtil<HomeHealthlogType>(HomeHealthlogType.class);
        util.exportExcel(response, list, "健康记录类型数据");
    }

    /**
     * 获取健康记录类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('type:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(homeHealthlogTypeService.selectHomeHealthlogTypeById(id));
    }

    /**
     * 新增健康记录类型
     */
    @PreAuthorize("@ss.hasPermi('type:type:add')")
    @Log(title = "健康记录类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HomeHealthlogType homeHealthlogType)
    {
        return toAjax(homeHealthlogTypeService.insertHomeHealthlogType(homeHealthlogType));
    }

    /**
     * 修改健康记录类型
     */
    @PreAuthorize("@ss.hasPermi('type:type:edit')")
    @Log(title = "健康记录类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HomeHealthlogType homeHealthlogType)
    {
        return toAjax(homeHealthlogTypeService.updateHomeHealthlogType(homeHealthlogType));
    }

    /**
     * 删除健康记录类型
     */
    @PreAuthorize("@ss.hasPermi('type:type:remove')")
    @Log(title = "健康记录类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(homeHealthlogTypeService.deleteHomeHealthlogTypeByIds(ids));
    }
}
